﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL_MechSys;
using DTO_MechSys;
using System.Threading;

namespace FORMS_MechSys
{
    public partial class frmPrincipal : Form
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmPrincipal));
        BLLProduto bllProduto = new BLLProduto();
        BLLCor bllCor = new BLLCor();
        BLLPropaganda bllPropaganda = new BLLPropaganda();
        DTOCor dtoCorPrincipal = new DTOCor();
        DTOCor dtoCorFundo = new DTOCor();
        DTOCor dtoCorLetra = new DTOCor();
        DTOCor dtoCorDataGrid = new DTOCor();
        
            frmAteLogo frmateLogo = new frmAteLogo();



        frmBemVindo frmbemVindo = new frmBemVindo(BLLUtilitarios.FuncionarioLogado);
        DateTime InicioSessao;
        DateTime FimSessao;
        DateTime MenuOpcoesOpened;

        public frmPrincipal()
        {
            InitializeComponent();
            SetColors();
            tlpOpcoes.RowStyles[0].Height = 0;
            tlpOpcoes.RowStyles[1].Height = 0;
            LoadPropagandas();
            InicioSessao = DateTime.Now;
            tsslblUsuario.Text = BLLUtilitarios.FuncionarioLogado;

        }
        private void SetColors()
        {
            dtoCorPrincipal = bllCor.Buscar("Principal");
            cadastrarToolStripMenuItem1.BackColor = agendamentoToolStripMenuItem.BackColor = estoqueToolStripMenuItem.BackColor =
                sairToolStripMenuItem.BackColor = mensagensToolStripMenuItem.BackColor = mensagensToolStripMenuItem.BackColor =
                logoffToolStripMenuItem.BackColor = configuraçõesToolStripMenuItem.BackColor = btnPagamento.BackColor = logoffToolStripMenuItem.BackColor =
            btnEntradaSaidaVeiculo.BackColor = btnOrcamento.BackColor = btnServicosPendentes.BackColor = btnVendaProduto.BackColor = btnClientesAgendados.BackColor = btnTarefa.BackColor = dtoCorPrincipal.Cor;
            btnRegistros.BackColor = btnRezise1.BackColor = btnRezise2.BackColor = btnRezise3.BackColor = btnRezise4.BackColor = dtoCorPrincipal.Cor;
            tlpBarraRight.BackColor = tlpBarraLeft.BackColor = tlpTitulo.BackColor = statusStrip1.BackColor = dtoCorPrincipal.Cor;
            tlpOpcoes.BackColor = pcbLogo.BackColor = statuslbl.BackColor = tlpMenuStrip.BackColor = dtoCorPrincipal.Cor;
            btn_cadastrarCliente.BackColor = btn_CadastrarCategoria.BackColor = btn_cadastrarFerramenta.BackColor = btn_cadastrarFornecedor.BackColor =
                btn_cadastrarFuncionario.BackColor = btn_cadastrarGasto.BackColor = btn_cadastrarProduto.BackColor = btn_cadastrarServico.BackColor =
                btn_cadastrarTarefa.BackColor = btn_cadastrarVeiculo.BackColor = btnVisualizarAgendamento.BackColor = btnPagamento.BackColor =
                btnAgendar.BackColor = dtoCorPrincipal.Cor;

            dtoCorFundo = bllCor.Buscar("Fundo");
            tlpPrincipal.BackColor = dtoCorFundo.Cor;

            dtoCorLetra = bllCor.Buscar("Letra");
            btnEntradaSaidaVeiculo.ForeColor = btnOrcamento.ForeColor = btnServicosPendentes.ForeColor = btnVendaProduto.ForeColor = btnClientesAgendados.ForeColor = btnTarefa.ForeColor = dtoCorLetra.Cor;
            btnRegistros.ForeColor = btnRezise1.ForeColor = btnRezise2.ForeColor = btnRezise3.ForeColor = btnRezise4.ForeColor = dtoCorLetra.Cor;
            lblResize1.ForeColor = lblResize2.ForeColor = lblResize3.ForeColor = lblResize4.ForeColor = lblTitulo.ForeColor = statuslbl.ForeColor = dtoCorLetra.Cor;
            sairToolStripMenuItem.ForeColor = cadastrarToolStripMenuItem1.ForeColor = agendamentoToolStripMenuItem.ForeColor = estoqueToolStripMenuItem.ForeColor = configuraçõesToolStripMenuItem.ForeColor = dtoCorLetra.Cor;
            btn_cadastrarCliente.ForeColor = btn_CadastrarCategoria.ForeColor = btn_cadastrarFerramenta.ForeColor = btn_cadastrarFornecedor.ForeColor =
                mensagensToolStripMenuItem.ForeColor = logoffToolStripMenuItem.ForeColor =
                btn_cadastrarFuncionario.ForeColor = btn_cadastrarGasto.ForeColor = btn_cadastrarProduto.ForeColor = btn_cadastrarServico.ForeColor =
                btn_cadastrarTarefa.ForeColor = btn_cadastrarVeiculo.ForeColor = btnVisualizarAgendamento.ForeColor = tsslblUsuario.ForeColor = tsslblTUsuario.ForeColor =
                btnAgendar.ForeColor = dtoCorLetra.Cor;

            dtoCorDataGrid = bllCor.Buscar("DataGrid");
            dgvCarrosConcluidos.BackgroundColor = dgvCarrosPendentes.BackgroundColor = dgvProdutosEstoqueBaixo.BackgroundColor = dgvClientesCadastrados.BackgroundColor = dtoCorDataGrid.Cor;

            if ((dtoCorLetra.R + dtoCorLetra.G + dtoCorLetra.B) < 360 && dtoCorLetra.R != Color.White.R && dtoCorLetra.G != Color.White.G && dtoCorLetra.B != Color.White.B)
            {

                cadastrarToolStripMenuItem1.Image = this.cadastrarToolStripMenuItem1.Image = global::FORMS_MechSys.Properties.Resources.Add1;
                agendamentoToolStripMenuItem.Image = this.agendamentoToolStripMenuItem.Image = global::FORMS_MechSys.Properties.Resources.Clipboard1;
                configuraçõesToolStripMenuItem.Image = this.configuraçõesToolStripMenuItem.Image = global::FORMS_MechSys.Properties.Resources.Configuration;
                estoqueToolStripMenuItem.Image = this.estoqueToolStripMenuItem.Image = global::FORMS_MechSys.Properties.Resources.Boxplot1;
                sairToolStripMenuItem.Image = this.sairToolStripMenuItem.Image = global::FORMS_MechSys.Properties.Resources.Exit1;

                btnRezise1.BackgroundImage = btnRezise2.BackgroundImage = btnRezise3.BackgroundImage = btnRezise4.BackgroundImage = global::FORMS_MechSys.Properties.Resources.Resize1;
            }
            else
            {
                cadastrarToolStripMenuItem1.Image = this.cadastrarToolStripMenuItem1.Image = global::FORMS_MechSys.Properties.Resources.Add;
                configuraçõesToolStripMenuItem.Image = this.configuraçõesToolStripMenuItem.Image = global::FORMS_MechSys.Properties.Resources.Configuration1;
                agendamentoToolStripMenuItem.Image = this.agendamentoToolStripMenuItem.Image = global::FORMS_MechSys.Properties.Resources.Clipboard;
                estoqueToolStripMenuItem.Image = this.estoqueToolStripMenuItem.Image = global::FORMS_MechSys.Properties.Resources.Boxplot;
                sairToolStripMenuItem.Image = this.sairToolStripMenuItem.Image = global::FORMS_MechSys.Properties.Resources.Exit;
                btnRezise1.BackgroundImage = btnRezise2.BackgroundImage = btnRezise3.BackgroundImage = btnRezise4.BackgroundImage = global::FORMS_MechSys.Properties.Resources.Resize;

            }
        }

        private void frmPrincipal_Activated(object sender, EventArgs e)
        {
            PopularGridsBarraRight();
            SetColors();
        }

        private void PopularGridsBarraRight()
        {
            //
            //Produtos Estoque Baixo
            dgvProdutosEstoqueBaixo.DataSource = null;
            dgvProdutosEstoqueBaixo.DataSource = bllProduto.DescricaoProdutosEstoqueBaixo();
            //

            //
            //Carros Pendentes
            dgvCarrosPendentes.DataSource = null;
            List<DTOOrdemPendente> listDtoOrdemPendente = new BLLOrdemPendente().BuscarOrdemPendentePendentes();
            if (listDtoOrdemPendente.Count > 0)
            {
                dgvCarrosPendentes.DataSource = listDtoOrdemPendente;
                dgvCarrosPendentes.Columns["DataEntrada"].Visible = false;
                dgvCarrosPendentes.Columns["DataEntrega"].Visible = false;
                dgvCarrosPendentes.Columns["Descricao"].Visible = false;
                //dgvCarrosPendentes.Columns["Dono"].Visible = false;
                dgvCarrosPendentes.Columns["OrdemPendenteID"].Visible = false;
                //dgvCarrosPendentes.Columns["Placa"].Visible = false;
                dgvCarrosPendentes.Columns["PrevisaoEntrega"].Visible = false;
                dgvCarrosPendentes.Columns["Prioridade"].Visible = false;
                dgvCarrosPendentes.Columns["Resumo"].Visible = false;
                dgvCarrosPendentes.Columns["Status"].Visible = false;
                dgvCarrosPendentes.Columns["Veiculo"].Visible = false;
                dgvCarrosPendentes.Columns["VeiculoID"].Visible = false;
            }
            //

            //
            //Carros Concluidos

            dgvCarrosConcluidos.DataSource = null;
            List<DTOOrdemPendente> listDtoOrdemConcluido = new BLLOrdemPendente().BuscarOrdemPendenteConcluidas();
            if (listDtoOrdemConcluido.Count > 0)
            {

                dgvCarrosConcluidos.DataSource = listDtoOrdemConcluido;
                dgvCarrosConcluidos.Columns["DataEntrada"].Visible = false;
                dgvCarrosConcluidos.Columns["DataEntrega"].Visible = false;
                dgvCarrosConcluidos.Columns["Descricao"].Visible = false;
                //dgvCarrosConcluidos.Columns["Dono"].Visible = false;
                dgvCarrosConcluidos.Columns["OrdemPendenteID"].Visible = false;
                //dgvCarrosConcluidos.Columns["Placa"].Visible = false;
                dgvCarrosConcluidos.Columns["PrevisaoEntrega"].Visible = false;
                dgvCarrosConcluidos.Columns["Prioridade"].Visible = false;
                dgvCarrosConcluidos.Columns["Resumo"].Visible = false;
                dgvCarrosConcluidos.Columns["Status"].Visible = false;
                dgvCarrosConcluidos.Columns["Veiculo"].Visible = false;
                dgvCarrosConcluidos.Columns["VeiculoID"].Visible = false;
                //
            }
        }

        private void toolStripButtonSair_Click(object sender, EventArgs e)
        {
            Fechar();
        }

        private void clientesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmClienteCadastro frmCliente = new frmClienteCadastro();
            frmCliente.ShowDialog();
        }

        private void funcionárioToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmFuncionarioCadastro frmFuncionario = new frmFuncionarioCadastro();
            frmFuncionario.ShowDialog();
        }

        private void fornecedorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmFornecedorCadastro frmFornecedor = new frmFornecedorCadastro();
            frmFornecedor.ShowDialog();
        }

        private void produtoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new frmProdutoCadastro().ShowDialog();
        }

        private void categoriaDeProdutoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new frmCategoriaCadastro().ShowDialog();
        }

        private void veículoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new frmVeiculoCadastro().ShowDialog();
        }

        private void serviçoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new frmServicoCadastro().ShowDialog();
        }

        private void tarefaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new frmTarefaCadastro().ShowDialog();
        }

        private void gastoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new frmGastoCadastro().ShowDialog();
        }

        private void ferramentaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new frmFerramentaCadastro().ShowDialog();
        }

        private void ReziseBarraRight(int linha)
        {
            bool bool1, bool3, bool5, bool7;
            double double1 = 0;
            double double3 = 0;
            double double5 = 0;
            double double7 = 0;

            if (this.tlpBarraRight.RowStyles[1].Height == (float)(0))
                bool1 = false;
            else
                bool1 = true;
            if (this.tlpBarraRight.RowStyles[3].Height == (float)(0))
                bool3 = false;
            else
                bool3 = true;
            if (this.tlpBarraRight.RowStyles[5].Height == (float)(0))
                bool5 = false;
            else
                bool5 = true;
            if (this.tlpBarraRight.RowStyles[7].Height == (float)(0))
                bool7 = false;
            else
                bool7 = true;

            int cont = 0;
            switch (linha)
            {
                case 1: bool1 = !bool1; break;
                case 3: bool3 = !bool3; break;
                case 5: bool5 = !bool5; break;
                case 7: bool7 = !bool7; break;
            }
            int open = 0;
            if (bool1)
                open++;
            if (bool3)
                open++;
            if (bool5)
                open++;
            if (bool7)
                open++;
            if (open > 0)
            {
                if (!bool1 && !bool3 && !bool5 && !bool7)
                    bool1 = true;

                if (bool1)
                    cont++;
                if (bool3)
                    cont++;
                if (bool5)
                    cont++;
                if (bool7)
                    cont++;

                double percent = 100 / (double)(cont);

                if (bool1)
                    double1 = percent;
                if (bool3)
                    double3 = percent;
                if (bool5)
                    double5 = percent;
                if (bool7)
                    double7 = percent;
                this.tlpBarraRight.RowStyles[8] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, (float)(0)));

            }
            else
            {
                this.tlpBarraRight.RowStyles[8] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, (float)(100)));
            }

            this.tlpBarraRight.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, (float)(double1)));
            this.tlpBarraRight.RowStyles[3] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, (float)(double3)));
            this.tlpBarraRight.RowStyles[5] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, (float)(double5)));
            this.tlpBarraRight.RowStyles[7] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, (float)(double7)));

        }

        private void btnRezise1_Click(object sender, EventArgs e)
        {
            ReziseBarraRight(1);
        }

        private void btnRezise2_Click(object sender, EventArgs e)
        {
            ReziseBarraRight(3);
        }

        private void btnRezise3_Click(object sender, EventArgs e)
        {
            ReziseBarraRight(5);
        }

        private void btnRezise4_Click(object sender, EventArgs e)
        {
            ReziseBarraRight(7);
        }

        private void lblResize4_DoubleClick(object sender, EventArgs e)
        {

            this.tlpBarraRight.RowStyles[1].Height = (float)(0);
            this.tlpBarraRight.RowStyles[3].Height = (float)(0);
            this.tlpBarraRight.RowStyles[5].Height = (float)(0);
            this.tlpBarraRight.RowStyles[7].Height = (float)(0);
            ReziseBarraRight(7);
        }

        private void lblResize1_DoubleClick(object sender, EventArgs e)
        {
            this.tlpBarraRight.RowStyles[1].Height = (float)(0);
            this.tlpBarraRight.RowStyles[3].Height = (float)(0);
            this.tlpBarraRight.RowStyles[5].Height = (float)(0);
            this.tlpBarraRight.RowStyles[7].Height = (float)(0);
            ReziseBarraRight(1);
        }

        private void lblResize2_DoubleClick(object sender, EventArgs e)
        {
            this.tlpBarraRight.RowStyles[1].Height = (float)(0);
            this.tlpBarraRight.RowStyles[3].Height = (float)(0);
            this.tlpBarraRight.RowStyles[5].Height = (float)(0);
            this.tlpBarraRight.RowStyles[7].Height = (float)(0);
            ReziseBarraRight(3);
        }

        private void lblResize3_DoubleClick(object sender, EventArgs e)
        {
            this.tlpBarraRight.RowStyles[1].Height = (float)(0);
            this.tlpBarraRight.RowStyles[3].Height = (float)(0);
            this.tlpBarraRight.RowStyles[5].Height = (float)(0);
            this.tlpBarraRight.RowStyles[7].Height = (float)(0);
            ReziseBarraRight(5);
        }

        private void configuraçõesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.tlpOpcoes.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            new frmPersonalizar().ShowDialog();
            LoadPropagandas();

        }

        private void cadastrarToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (tlpOpcoes.RowStyles[0].Height == 0)
            {
                this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 40F));
                this.tlpOpcoes.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
                this.tlpOpcoes.Size = new System.Drawing.Size(1362, 40);
                MenuOpcoesOpened = DateTime.Now;
            }
            else
            {
                this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
                this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            }
        }

        private void agendamentoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tlpOpcoes.RowStyles[1].Height == 0)
            {
                this.tlpOpcoes.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 40F));
                this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
                this.tlpOpcoes.Size = new System.Drawing.Size(1362, 40);
                MenuOpcoesOpened = DateTime.Now;
            }
            else
            {
                this.tlpOpcoes.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
                this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            }

        }

        private void btnAgendar_Click(object sender, EventArgs e)
        {
            this.tlpOpcoes.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            frmAgendamentoCadastro frmAgendamento = new frmAgendamentoCadastro();
            frmAgendamento.ShowDialog();

        }

        private void btnVisualizarAgendamento_Click(object sender, EventArgs e)
        {
            this.tlpOpcoes.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            frmAgendamentoListar frmListar = new frmAgendamentoListar();
            frmListar.ShowDialog();
        }

        private void btn_cadastrarCliente_Click(object sender, EventArgs e)
        {
            this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            new frmClienteCadastro().ShowDialog();
        }

        private void btn_cadastrarVeiculo_Click(object sender, EventArgs e)
        {
            this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            new frmVeiculoCadastro().ShowDialog();
        }

        private void btn_cadastrarProduto_Click(object sender, EventArgs e)
        {
            this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            new frmProdutoCadastro().ShowDialog();
        }

        private void btn_cadastrarServico_Click(object sender, EventArgs e)
        {
            this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            new frmServicoCadastro().ShowDialog();
        }

        private void btn_cadastrarFornecedor_Click(object sender, EventArgs e)
        {
            this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            new frmFornecedorCadastro().ShowDialog();
        }

        private void btn_cadastrarFuncionario_Click(object sender, EventArgs e)
        {
            this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            new frmFuncionarioCadastro().ShowDialog();
        }

        private void btn_cadastrarFerramenta_Click(object sender, EventArgs e)
        {
            this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            new frmFerramentaCadastro().ShowDialog();
        }

        private void btn_cadastrarTarefa_Click(object sender, EventArgs e)
        {
            this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            new frmTarefaCadastro().ShowDialog();
        }

        private void btn_cadastrarGasto_Click(object sender, EventArgs e)
        {
            this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            new frmGastoCadastro().ShowDialog();
        }

        private void btn_CadastrarCategoria_Click(object sender, EventArgs e)
        {
            this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            new frmCategoriaCadastro().ShowDialog();
        }

        private void btnClientesAgendados_Click(object sender, EventArgs e)
        {
            new frmAgendamentoListar().ShowDialog();
        }

        private void LoadPropagandas()
        {
            List<DTOPropaganda> listaPropaganda = new List<DTOPropaganda>();
            listaPropaganda = bllPropaganda.BuscarPropagandaCadastrados();

            pictureBox2.Image = pictureBox3.Image = pictureBox4.Image = pictureBox5.Image = pictureBox6.Image = pictureBox7.Image = pictureBox8.Image = pictureBox9.Image =
            pictureBox10.Image = pictureBox11.Image = pictureBox12.Image = pictureBox13.Image = pictureBox14.Image = pictureBox15.Image = pictureBox16.Image = pictureBox17.Image =
            pictureBox18.Image = pictureBox19.Image = pictureBox20.Image = pictureBox21.Image = pictureBox22.Image = pictureBox23.Image = pictureBox24.Image = pictureBox25.Image =
            pictureBox26.Image = pictureBox27.Image = pictureBox28.Image = pictureBox29.Image = pictureBox30.Image = pictureBox31.Image = pictureBox32.Image = pictureBox33.Image = null;



            this.tlpLinhasPropagandas.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpLinhasPropagandas.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpLinhasPropagandas.RowStyles[2] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpLinhasPropagandas.RowStyles[3] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
            this.tlpLinhasPropagandas.Size = new System.Drawing.Size(741, 0);

            int largDisp = tlpPropagandaLinha1.Size.Width;
            int contPropagandas = 0;

            //primeira Linha
            if (contPropagandas < listaPropaganda.Count)
            {

                tlpPropagandaLinha1.ColumnStyles[1] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha1.ColumnStyles[3] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha1.ColumnStyles[5] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha1.ColumnStyles[7] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha1.ColumnStyles[9] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha1.ColumnStyles[11] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha1.ColumnStyles[13] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);

                this.tlpLinhasPropagandas.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 45F));
                this.tlpLinhasPropagandas.Size = new System.Drawing.Size(741, 45);
                for (int i = 0; i < 8; i++)
                {
                    if (contPropagandas == listaPropaganda.Count)
                    {
                        largDisp = -1;
                        contPropagandas--;
                    }
                    if (largDisp < (listaPropaganda[contPropagandas].Largura + 40))
                    {
                        switch (i)
                        {
                            case 0: tlpPropagandaLinha1.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 1: tlpPropagandaLinha1.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 2: tlpPropagandaLinha1.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 3: tlpPropagandaLinha1.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 4: tlpPropagandaLinha1.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 5: tlpPropagandaLinha1.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 6: tlpPropagandaLinha1.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 7: tlpPropagandaLinha1.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                        }

                        if (largDisp == -1)
                            contPropagandas++;
                    }
                    else
                    {
                        switch (i)
                        {
                            case 0:
                                tlpPropagandaLinha1.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                pictureBox2.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox2.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 1:
                                tlpPropagandaLinha1.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha1.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox3.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox3.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 2:
                                tlpPropagandaLinha1.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha1.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox4.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox4.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 3:
                                tlpPropagandaLinha1.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha1.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox5.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox5.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 4:
                                tlpPropagandaLinha1.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha1.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox6.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox6.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 5:
                                tlpPropagandaLinha1.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha1.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox7.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox7.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 6:
                                tlpPropagandaLinha1.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha1.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox8.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox8.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 7:
                                tlpPropagandaLinha1.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha1.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                pictureBox9.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox9.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                        }
                        largDisp -= listaPropaganda[contPropagandas].Largura;
                        contPropagandas++;
                    }
                }
            }
            largDisp = tlpPropagandaLinha2.Size.Width;


            //Segunda Linha
            if (contPropagandas < listaPropaganda.Count)
            {
                tlpPropagandaLinha2.ColumnStyles[1] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha2.ColumnStyles[3] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha2.ColumnStyles[5] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha2.ColumnStyles[7] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha2.ColumnStyles[9] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha2.ColumnStyles[11] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha2.ColumnStyles[13] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);

                this.tlpLinhasPropagandas.RowStyles[1] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 45F));

                this.tlpLinhasPropagandas.Size = new System.Drawing.Size(741, 90);
                for (int i = 0; i < 8; i++)
                {
                    if (contPropagandas == listaPropaganda.Count)
                    {
                        largDisp = -1;
                        contPropagandas--;
                    }
                    if (largDisp < (listaPropaganda[contPropagandas].Largura + 40))
                    {
                        switch (i)
                        {
                            case 0: tlpPropagandaLinha2.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 1: tlpPropagandaLinha2.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 2: tlpPropagandaLinha2.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 3: tlpPropagandaLinha2.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 4: tlpPropagandaLinha2.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 5: tlpPropagandaLinha2.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 6: tlpPropagandaLinha2.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 7: tlpPropagandaLinha2.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                        }
                        if (largDisp == -1)
                            contPropagandas++;
                    }
                    else
                    {
                        switch (i)
                        {
                            case 0:
                                tlpPropagandaLinha2.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox10.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox10.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 1:
                                tlpPropagandaLinha2.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox11.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox11.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 2:
                                tlpPropagandaLinha2.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox12.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox12.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 3:
                                tlpPropagandaLinha2.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox13.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox13.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 4:
                                tlpPropagandaLinha2.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox14.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox14.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 5:
                                tlpPropagandaLinha2.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox15.Image = listaPropaganda[contPropagandas].Imagem;
                                int a = listaPropaganda[contPropagandas].Indice;
                                pictureBox15.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 6:
                                tlpPropagandaLinha2.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha2.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox16.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox16.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 7:
                                tlpPropagandaLinha2.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha2.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                pictureBox17.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox17.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                        }
                        largDisp -= listaPropaganda[contPropagandas].Largura;
                        contPropagandas++;
                    }
                }
            }
            largDisp = tlpPropagandaLinha3.Size.Width;

            //Terceira Linha
            if (contPropagandas < listaPropaganda.Count)
            {

                tlpPropagandaLinha3.ColumnStyles[1] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha3.ColumnStyles[3] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha3.ColumnStyles[5] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha3.ColumnStyles[7] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha3.ColumnStyles[9] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha3.ColumnStyles[11] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha3.ColumnStyles[13] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);

                this.tlpLinhasPropagandas.RowStyles[2] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 45F));
                this.tlpLinhasPropagandas.Size = new System.Drawing.Size(741, 135);
                for (int i = 0; i < 8; i++)
                {
                    if (contPropagandas == listaPropaganda.Count)
                    {
                        largDisp = -1;
                        contPropagandas--;
                    }
                    if (largDisp < (listaPropaganda[contPropagandas].Largura + 40))
                    {
                        switch (i)
                        {
                            case 0: tlpPropagandaLinha3.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 1: tlpPropagandaLinha3.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 2: tlpPropagandaLinha3.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 3: tlpPropagandaLinha3.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 4: tlpPropagandaLinha3.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 5: tlpPropagandaLinha3.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 6: tlpPropagandaLinha3.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 7: tlpPropagandaLinha3.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                        }
                        if (largDisp == -1)
                            contPropagandas++;
                    }
                    else
                    {
                        switch (i)
                        {
                            case 0:
                                tlpPropagandaLinha3.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha3.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                pictureBox18.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox18.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 1:
                                tlpPropagandaLinha3.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha3.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox19.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox19.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 2:
                                tlpPropagandaLinha3.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha3.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox20.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox20.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 3:
                                tlpPropagandaLinha3.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha3.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox21.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox21.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 4:
                                tlpPropagandaLinha3.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha3.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox22.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox22.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 5:
                                tlpPropagandaLinha3.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha3.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox23.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox23.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 6:
                                tlpPropagandaLinha3.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                pictureBox24.Image = listaPropaganda[contPropagandas].Imagem;
                                tlpPropagandaLinha3.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox24.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 7:
                                tlpPropagandaLinha3.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha3.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                pictureBox25.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox25.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                        }
                        largDisp -= listaPropaganda[contPropagandas].Largura;
                        contPropagandas++;
                    }
                }
            }

            largDisp = tlpPropagandaLinha4.Size.Width;

            //Quarta Linha
            if (contPropagandas < listaPropaganda.Count)
            {
                tlpPropagandaLinha4.ColumnStyles[1] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha4.ColumnStyles[3] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha4.ColumnStyles[5] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha4.ColumnStyles[7] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha4.ColumnStyles[9] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha4.ColumnStyles[11] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);
                tlpPropagandaLinha4.ColumnStyles[13] = new ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0);

                this.tlpLinhasPropagandas.RowStyles[3] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 45F));
                this.tlpLinhasPropagandas.Size = new System.Drawing.Size(741, 180);
                for (int i = 0; i < 8; i++)
                {
                    if (contPropagandas == listaPropaganda.Count)
                    {
                        largDisp = -1;
                        contPropagandas--;
                    }
                    if (largDisp < (listaPropaganda[contPropagandas].Largura + 40))
                    {
                        switch (i)
                        {
                            case 0: tlpPropagandaLinha4.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 1: tlpPropagandaLinha4.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 2: tlpPropagandaLinha4.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 3: tlpPropagandaLinha4.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 4: tlpPropagandaLinha4.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 5: tlpPropagandaLinha4.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 6: tlpPropagandaLinha4.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                            case 7: tlpPropagandaLinha4.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)0)); break;
                        }
                        if (largDisp == -1)
                            contPropagandas++;
                    }
                    else
                    {
                        switch (i)
                        {
                            case 0:
                                tlpPropagandaLinha4.ColumnStyles[0] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));

                                tlpPropagandaLinha4.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                pictureBox26.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox26.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 1:
                                tlpPropagandaLinha4.ColumnStyles[1] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[2] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha4.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox27.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox27.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 2:
                                tlpPropagandaLinha4.ColumnStyles[3] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[4] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha4.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox28.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox28.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 3:
                                tlpPropagandaLinha4.ColumnStyles[5] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[6] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha4.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox29.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox29.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 4:
                                tlpPropagandaLinha4.ColumnStyles[7] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[8] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha4.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox30.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox30.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 5:
                                tlpPropagandaLinha4.ColumnStyles[9] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[10] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha4.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox31.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox31.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 6:
                                tlpPropagandaLinha4.ColumnStyles[11] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[12] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                tlpPropagandaLinha4.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)0));
                                pictureBox32.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox32.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                            case 7:
                                tlpPropagandaLinha4.ColumnStyles[13] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, (float)100));
                                tlpPropagandaLinha4.ColumnStyles[14] = (new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, (float)listaPropaganda[contPropagandas].Largura));
                                pictureBox33.Image = listaPropaganda[contPropagandas].Imagem;
                                pictureBox33.Margin = new System.Windows.Forms.Padding(3, (int)((20 - listaPropaganda[contPropagandas].Altura)), 3, (int)((20 - listaPropaganda[contPropagandas].Altura)));
                                break;
                        }
                        largDisp -= listaPropaganda[contPropagandas].Largura;
                        contPropagandas++;
                    }
                }
            }
        }

        private void btnEntradaSaidaVeiculo_Click(object sender, EventArgs e)
        {
            new frmCarrosNaOficina().ShowDialog();
        }

        private void frmPrincipal_Load(object sender, EventArgs e)
        {

        }

        private void btnOrcamento_Click(object sender, EventArgs e)
        {
            new frmOrcamento().ShowDialog();
        }

        private void btnServicosPendentes_Click(object sender, EventArgs e)
        {
            new frmServicosPendentes().ShowDialog();
        }

        private void btnVendaProduto_Click(object sender, EventArgs e)
        {
            new frmVenda().ShowDialog();
        }

        private void btnPagamento_Click(object sender, EventArgs e)
        {
            new frmFormaPagementoCadastro().ShowDialog();

        }


        private void Fechar()
        {
            if (new frmMessageBox().Show("Tem Certeza que Deseja Fechar o Programa?", "Sair", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    //this.Dispose();
                    this.Enabled = false;
                    timerAteLogo.Enabled = true;
                    FimSessao = DateTime.Now;
                }
                catch (Win32Exception)
                {
                    Application.Exit();
                }
            }

        }
        private void frmPrincipal_FormClosing(object sender, FormClosingEventArgs e)
        {
            Fechar();
            e.Cancel = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            DTOBemVindo dtobemVindo = new BLLBemVindo().Exibir();
            if (dtobemVindo.Exibir)
            {
                frmbemVindo = new frmBemVindo(BLLUtilitarios.FuncionarioLogado);
                if (DateTime.Now >= InicioSessao.AddMilliseconds(80))
                {
                    frmbemVindo.Show();
                    timerBemVindo.Enabled = false;
                    timerFecharBemVindo.Enabled = true;
                    //InicioSessao = DateTime.Now;
                }
            }
        }

        private void estoqueToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new frmEstoque().ShowDialog();
        }

        private void ajudaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            timerBemVindo.Enabled = true;
        }

        private void logoffToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.ShowInTaskbar = false;
            BLLUtilitarios.FuncionarioLogadoID = 0;
            BLLUtilitarios.FuncionarioLogado = "";
            SetColors();
            frmSplashScreen frmSplash = new frmSplashScreen();
            frmSplash.ExibirLogin();
            frmSplash.ShowDialog();
            tsslblUsuario.Text = BLLUtilitarios.FuncionarioLogado;
            this.ShowInTaskbar = true;
        }

        private void timerFecharBemVindo_Tick(object sender, EventArgs e)
        {
            DTOBemVindo dtobemVindo = new BLLBemVindo().Exibir();
            if (DateTime.Now >= InicioSessao.AddSeconds(dtobemVindo.Tempo))
            {
                frmbemVindo.Dispose();
                timerFecharBemVindo.Enabled = false;

            }
        }

        private void tlpOpcoes_SizeChanged(object sender, EventArgs e)
        {
            if (tlpOpcoes.Height > 0)
            {
                timerMenuStrip.Enabled = true;
                MenuOpcoesOpened = DateTime.Now;
            }
            else
            {
                timerMenuStrip.Enabled = false;
            }
        }

        private void timerMenuStrip_Tick(object sender, EventArgs e)
        {
            if (DateTime.Now > MenuOpcoesOpened.AddSeconds(10))
            {
                this.tlpOpcoes.RowStyles[0] = (new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F));
                this.tlpOpcoes.Size = new System.Drawing.Size(1362, 0);
            }
        }

        private void mensagensToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new frmMensagemCliente().ShowDialog();
        }

        private void timerAteLogo_Tick(object sender, EventArgs e)
        {
            frmateLogo = new frmAteLogo();
            if (DateTime.Now >= FimSessao.AddMilliseconds(80))
            {
                frmateLogo.Show();
                this.WindowState = FormWindowState.Minimized;
                timerAteLogo.Enabled = false;
                timerFecharAteLogo.Enabled = true;
                //InicioSessao = DateTime.Now;
            }
        }

        private void timerFecharAteLogo_Tick(object sender, EventArgs e)
        {
            if (DateTime.Now >= FimSessao.AddSeconds(3))
            {
                frmateLogo.Dispose();
                timerFecharAteLogo.Enabled = false;
                Environment.Exit(0);
            }
        }

        private void btnTarefa_Click(object sender, EventArgs e)
        {
            new frmMensagemCliente().ShowDialog();
        }

        private void btnRegistros_Click(object sender, EventArgs e)
        {
            new frmEstoque().ShowDialog();
        }

    }
}
